﻿/*******************************************************************************
 * Copyright © 2016-2020 北京网非科技有限公司 版权所有
 * Author: 北京网非科技有限公司
 * Description: 网非快速开发平台NET
 * Website：http://www.wfdot.com
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Mvc;
using CubicFWNet.Application.SystemManage;
using CubicFWNet.Common;
using CubicFWNet.Application.SystemSecurity;
using CubicFWNet.Data.SystemManage.Model;
using CubicFWNet.Data.SystemSecurity.Model;

namespace CubicFWNet.Mvc.Filter
{
    /**
     *tyj  2016年12月19日10:25:32
     *删除 记录过滤器 
     *Action必须返回ContentResult，ContentResult的Content必须是ResponseResult
     **/
    public class DeleteAttribute : ActionFilterAttribute
    {
        private readonly OperatorLogApp _logApp = new OperatorLogApp();

        private IDictionary<string, object> _actionParameters { get; set; }
        private OperatorModel _user = OperatorProvider.Provider.GetCurrent();
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            var result = filterContext.Result as ContentResult;
            if (null == result)
                return;
            var responseResult = result.Content.ToObject<ResponseResult>();
            if (null == responseResult)
                return;
            if (responseResult.Status == ResultType.success.ToString())
            {
                var resultSub = responseResult.Data.ToString();
                _logApp.Add(new OperatorLog()
                {
                    UserId = _user.UserId,
                    Name = _user.FamilyName,
                    Description = resultSub,
                    ModuleUrl = filterContext.RouteData.Values["controller"].ToString() + "/" + filterContext.RouteData.Values["action"].ToString(),
                    Status = responseResult.Status,
                    EmOpeartor = EmOpeartor.delete
                });
            }            
            else
            {

            }

        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            _actionParameters = filterContext.ActionParameters;
        }

        //public override void OnResultExecuted(ResultExecutedContext filterContext)
        //{
        //    base.OnResultExecuted(filterContext);
        //}

        //public override void OnResultExecuting(ResultExecutingContext filterContext)
        //{
        //    base.OnResultExecuting(filterContext);
        //}

    }
}